from selenium import webdriver
from selenium.webdriver.chrome.options import Options



class ChromeBot(object):

    def Search(self, url):
        chrome_options = Options()
        chrome_options.add_argument("start-maximized")
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-gpu')
        chrome_options.add_argument('--disable-dev-shm-usage')
        chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
        chrome_options.add_experimental_option("useAutomationExtension", False)
        prefs = {'profile.managed_default_content_settings.images': 2}
        chrome_options.add_experimental_option('prefs', prefs)
        driver = webdriver.Chrome(options=chrome_options)
        with open('cache/stealth.min.js') as f:
            js = f.read()
            driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
                "source": js
            })
        driver.set_window_size(1920, 1080)
        try:
            driver.get(url)
            content = driver.page_source
            driver.quit()
            return content
        except Exception as e:
            print(e)
            driver.quit()
            return None


if __name__ == '__main__':
    bot = ChromeBot()
    bot.Search('')
